<template>
  <view class="detail-container">
    <view class="header">
      <view class="back-btn" @tap="goBack">
        <text class="back-icon">←</text>
      </view>
      <text class="title">活动详情</text>
    </view>
    
    <view v-if="loading" class="loading">
      <text>加载中...</text>
    </view>
    <view v-else-if="error" class="error">
      <text>{{ error }}</text>
    </view>
    <view v-else class="activity-content">
      <view class="content-section">
        <text class="content-text">{{ activity.content }}</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      activityId: '',
      activity: {
        content: ''
      },
      loading: false,
      error: ''
    }
  },
  onLoad(options) {
    if (options && options.id) {
      this.activityId = options.id
      this.fetchActivityDetail()
    }
  },
  methods: {
    goBack() {
      uni.navigateBack()
    },
    fetchActivityDetail() {
      this.loading = true
      this.error = ''
      
      // 由于没有详情接口，我们从列表接口获取所有数据后筛选对应ID的活动
      uni.request({
        url: 'http://localhost:8080/cc/activity/lists',
        method: 'GET',
        success: (res) => {
          if (res.data && res.data.rows) {
            const targetActivity = res.data.rows.find(item => item.id === this.activityId)
            if (targetActivity) {
              this.activity = targetActivity
            } else {
              this.error = '未找到该活动信息'
            }
          } else {
            this.error = '获取活动详情失败'
          }
        },
        fail: (err) => {
          console.error('获取活动详情失败:', err)
          this.error = '网络请求失败，请稍后重试'
        },
        complete: () => {
          this.loading = false
        }
      })
    }
  }
}
</script>

<style scoped>
.detail-container {
  padding: 20rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
}

.header {
  display: flex;
  align-items: center;
  padding: 20rpx 0;
  margin-bottom: 20rpx;
  background-color: #ffffff;
  padding-left: 20rpx;
  border-radius: 12rpx;
}

.back-btn {
  padding: 20rpx;
}

.back-icon {
  font-size: 40rpx;
}

.title {
  font-size: 36rpx;
  font-weight: bold;
  margin-left: 20rpx;
}

.loading,
.error {
  text-align: center;
  padding: 100rpx 0;
  color: #999999;
  font-size: 32rpx;
}

.error {
  color: #e64340;
}

.activity-content {
  background-color: #ffffff;
  border-radius: 12rpx;
  padding: 30rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
}

.content-section {
  margin-bottom: 20rpx;
}

.content-text {
  font-size: 32rpx;
  color: #333333;
  line-height: 1.8;
  white-space: pre-wrap;
}
</style>